const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require("clean-webpack-plugin");
const webpack = require('webpack');
module.exports = {
  devtool: 'eval-source-map',
  entry:  {
    vendors:['jquery'],
    main:__dirname + "/src/main.js",//已多次提及的唯一入口文件
    // main2:__dirname + "/src/main2.js",
  },
  output: {
    path: __dirname + "/build",//打包后的文件存放的地方
    filename: "[name]-[chunkHash:8].js"//模块指纹
  },
  devServer: {
    // contentBase: "./",//本地服务器所加载的页面所在的目录
    historyApiFallback: true,//不跳转
    inline: true//实时刷新
  } ,
  module:{
    rules:[
      {
        test:/\.css$/,
        use:[
        {
          loader:"style-loader"  // style-loader 在前面否则报错
        },
        {
          loader:"css-loader",
          options: {
                    modules: true, // 指定启用css modules
                    localIdentName: '[name]__[local]--[hash:base64:5]' // 指定css的类名格式
                }

        },
        ]
      }
    ]
  },
  plugins: [
          new HtmlWebpackPlugin({
              template: __dirname + "/src/views/index.html",
              // chunksSortMode:"dependency"
          }),
          new CleanWebpackPlugin('build/*.*', {
              root: __dirname,
              verbose: true,
              dry: false,
          }),
          // 打包第三方类库 
          new webpack.optimize.CommonsChunkPlugin( {
              names:['vendors','manifest'],  // 添加manifest 保证vendors 的模块hash不变，
          }),
          // 暴露全局变量
          new webpack.ProvidePlugin({
              $: "jquery",
              jQuery: "jquery"
          }),
      ],

}
